package com.wyh.wyhblog.controller;

import com.github.pagehelper.PageInfo;
import com.wyh.wyhblog.model.TArticle;
import com.wyh.wyhblog.service.TAeticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Calendar;
import java.util.List;

/**
 * @author wuyuhan
 * @date 2020/12/7 21:24
 */
@Controller
public class TAeticleController {

    @Autowired
    TAeticleService tAeticleService;

    @RequestMapping("/toLoginPage")
    public String toLoginPage(Model model){

        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        return "login";
    }

    @RequestMapping("/articleList")
    public String articleList(Model model,
                               @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                               @RequestParam(required = false, defaultValue = "2") Integer pageSize){

        PageInfo<TArticle> tArticles = tAeticleService.selectAll(pageNum, pageSize);
        model.addAttribute("aList", tArticles);
        model.addAttribute("active", "articleList");
        return "index";
    }
}
